﻿Imports System.Windows.Threading
Imports System.Collections.ObjectModel
Imports System.ComponentModel
Imports System.Text

Partial Public Class Page
	Inherits UserControl

	Public Sub New()
		InitializeComponent()
	End Sub

	Private _People As ObservableCollection(Of Person) = New ObservableCollection(Of Person)

	Private Sub Page_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
		_People.Add(New Person() With {.FirstName = "Scott", .LastName = "Blue"})
		_People.Add(New Person() With {.FirstName = "John", .LastName = "Doe"})
		grid.ItemsSource = _People
		tmr.Interval = New TimeSpan(0, 0, 5)
		tmr.Start()
	End Sub

	Private WithEvents tmr As DispatcherTimer = New DispatcherTimer()

	Public Class Person
		Private _FirstName As String
		Private _LastName As String
		Public Property FirstName() As String
			Get
				Return _FirstName
			End Get
			Set(ByVal value As String)
				_FirstName = value
			End Set
		End Property
		Public Property LastName() As String
			Get
				Return _LastName
			End Get
			Set(ByVal value As String)
				_LastName = value
			End Set
		End Property
	End Class

	Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick
		_People.Add(New Person() With {.FirstName = "Tick", .LastName = GetRandomString(10, False)})
	End Sub

	Private Function GetRandomString(ByVal size As Integer, ByVal lowerCase As Boolean) As String
		Dim builder As New StringBuilder()
		Dim random As New Random
		Dim ch As Char
		For i As Integer = 0 To size
			ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)))
			builder.Append(ch)
		Next
		If lowerCase Then Return builder.ToString.ToLower
		Return builder.ToString

	End Function

End Class
